<template>
	<view>
		<image src="../../static/code-bg.png" class="code-bg" mode=""></image>
		<view class="content">
			<image src="../../static/logo-radio.png" class="logo" mode=""></image>
			<text class="code-text" >我的邀请码</text>
			<text class="code" @click="copy" v-if="userData">{{userData.userNo}}</text>
			<text class="copy" @click="copy">点击邀请码复制</text>
			<view class="qrcode">
				<uv-qrcode ref="qrcode" size="442rpx"  :value="invite"></uv-qrcode>
			</view>
			<button class="btn" @click="share">立即分享</button>
		</view>
	</view>
</template>

<script setup>
	import {
		user,
		constantGet
	} from '@/util/api.js'
	import { ref } from 'vue';
	const userData = ref()
	const invite = ref()
	const qrcode = ref()
	import {
		onShow
	} from '@dcloudio/uni-app'
	onShow(() => {
		console.log(9)
		
		getUser()
		
	})
	// 获取当前登录用户信息
	const getUser = async() =>{
		const result = await user()
		
		if(result.code==200){
			userData.value = result.data
		}else{
			userData.value = null
		}
		getInvitebConfig()
		console.log(userData.value)
	}
	// 邀请链接配置
	const getInvitebConfig = async ()=>{
		const result = await constantGet({key:"invite_url"})
		if(result.code==200){
			let str  = JSON.parse(result.data.data)
			console.log(str)
			invite.value = str.value + '?invcode='+userData.value.userNo
			console.log('------',invite.value)
		}
		
		
	}
	const copy = (text) => {
		uni.setClipboardData({
			data: String(userData.value.userNo),
			success: function() {
				console.log('success');
			}
		});
	}
	const share = ()=>{
		
		// qrcode.value.toTempFilePath({
		// 	success:(res=>{
		// 		console.log("成功",res)
		// 		uni.saveImageToPhotosAlbum({
		// 			filePath: res.tempFilePath,
		// 			success: function () {
		// 				console.log('save success');
		// 			}
		// 		});
		// 	})
		// })
		uni.showModal({
			title:"提示",
			content:"请保存二维码到到相册后去分享",
			success: (ret) => {
				if(ret.confirm){
					qrcode.value.save({
						success:(res)=>{
							console.log("res")
							uni.showToast({
								title:"保存成功",
								icon:"none"
							})
						}
					})
				}
			}
		})
		
	}
</script>

<style lang="scss" scoped>
	.code-bg{
		width: 750rpx;
		height: 1622rpx;
	}
	.content{
		width: 673rpx;
		height: 1190rpx;
		background: #FFFFFF;
		box-shadow: 0px 15rpx 38rpx 2rpx rgba(49,54,70,0.05);
		border-radius: 23rpx;
		
		position: absolute;
		top: 156rpx;
		left: 38rpx;
		.logo{
			margin: -85rpx auto 38rpx;
			width:174rpx;
			height: 174rpx;
			display: block;
		}
		.code-text{
			display: block;
			text-align: center;
			color: #333;
			font-size: 38rpx;
			margin-bottom: 38rx;
		}
		.code{
			display: block;
			width: 596rpx;
			height: 100rpx;
			background: #F6F6FF;
			border-radius: 71rpx;
			margin: 38rpx auto ;
			text-align: center;
			line-height: 100rpx;
			color: #0265FF;
			font-size: 38rpx;
		}
		.copy{
			color: #999;
			display: block;
			text-align: center;
			font-size: 38rpx;
		}
		.qrcode{
			width: 442rpx;
			height: 442rpx;
			margin: 77rpx auto 38rpx;
		}
		.btn{
			width: 596rpx;
			height: 100rpx;
			background: #0265FF;
			box-shadow: 0px 12 38rpx 2rpx rgba(0,4,61,0.12);
			border-radius: 71rpx;
			display: block;
			margin: 0 auto;
			color: #fff;
			font-size: 38rpx;
			font-weight: 800;
			text-align: center;
			line-height: 100rpx;
		}
	}
</style>
